iT邦幫忙

2022 iThome 鐵人賽

DAY 25
0
Web 3

當 APP develop 遇上 web3 與 Metaverse 浪潮 系列 第 25

[Day 貳拾五] 來開發元宇宙中藥鋪吧14 - 建立測試空間

  • 分享至 

  • xImage
  •  

為了之後可以建立 中藥NFT盲盒 並且導入我們的 元宇宙中藥鋪
所以開始建立一個 lab

動態讀取遠端 Gltf 素材

import { useLoader, useThree } from '@react-three/fiber'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
import { Suspense } from 'react'
import * as THREE from 'three'
import { useGLTF, Clone, MeshDistortMaterial, OrbitControls, Bounds, BakeShadows, TransformControls, Html } from '@react-three/drei'

export default function GltfScene(props) {
  // const gltf = useGLTF('https://modelviewer.dev/shared-assets/models/NeilArmstrong.glb')
  const gltf = useGLTF(props.model)

  const cloneScene = gltf.scene.clone()

  var mroot = cloneScene
  var bbox = new THREE.Box3().setFromObject(mroot)
  var cent = bbox.getCenter(new THREE.Vector3())
  var size = bbox.getSize(new THREE.Vector3())

  //Rescale the object to normalized space
  var maxAxis = Math.max(size.x, size.y, size.z)
  mroot.scale.multiplyScalar(1.0 / maxAxis)
  bbox.setFromObject(mroot)
  bbox.getCenter(cent)
  bbox.getSize(size)
  //Reposition to 0,halfY,0
  mroot.position.copy(cent).multiplyScalar(-1)
  mroot.position.y -= size.y * 0.5

  // const { nodes } = useLoader(GLTFLoader, )
  return (
    <Suspense fallback={null} scale={1}>
      <primitive scale={10} receiveShadow castShadow object={cloneScene} />

      {/* <primitive scale={10} receiveShadow castShadow object={gltf.scene} /> */}
      <mesh position={[0, 0, 0]} scale={5 * 2}>
        <boxBufferGeometry />
        <meshStandardMaterial opacity={0.1} transparent color="#A2A2cA" />
      </mesh>
    </Suspense>
  )
}

// export default function GLTFModel(props: GLTFModelProps) {
//   const gltf = useGLTF(props.model);
//   return <primitive object={gltf.scene} />;
// }

// <Canvas>
//  <Suspense fallback={null}>
//     <GLTFModel model={glbUrl}/>
//  </Suspense>
// </Canvas>

function _GltfScene() {
  const gltf = useLoader(GLTFLoader, 'https://modelviewer.dev/shared-assets/models/NeilArmstrong.glb')
  const { nodes, materials } = gltf
  const { scene } = useThree()
  // materials["UnitBox"]

  const cloneScene = gltf.scene.clone()
  return (
    <Suspense fallback={null} scale={1}>
      {/* <Clone>
        <primitive object={cloneScene} />
      </Clone> */}
      <Clone>
        <primitive object={cloneScene} />
      </Clone>
      {/* <primitive object={gltf.scene} /> */}
      {/* <Clone object={gltf.scene} /> */}
      <mesh position={[0, 0, 0]} scale={5}>
        <boxBufferGeometry />
        <meshStandardMaterial color="#A2A2cA" />
      </mesh>
    </Suspense>
  )
}


上一篇
[Day 貳拾肆] 來開發元宇宙中藥鋪吧12 - 如何處理場景切換焦點與旋轉置焦點物間
下一篇
[Day 貳拾陸] 來開發元宇宙中藥鋪吧14 - 中藥包NFT???
系列文
當 APP develop 遇上 web3 與 Metaverse 浪潮 30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言